﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CONTROLLER;
using ENTITY;
using DevExpress.XtraEditors;
namespace frm_view
{
    public partial class frmMonHoc : Form
    {
        ctrls_MonHoc objMonHoc = new ctrls_MonHoc();
        EN_MonHoc obj_en = new EN_MonHoc();
        public bool IsInsert = false;
        public EventHandler LamMoi;
        public string ID = "";
        public frmMonHoc()
        {
            InitializeComponent();
        }

        private void frmMonHoc_Load(object sender, EventArgs e)
        {
            if (IsInsert == false)
            {
                DataTable dt = new DataTable();
                dt = objMonHoc.MonHoc_Select_ALL();
                txtMaMon.Text = dt.Rows[0]["MaMon"].ToString();
                txtTenMon.Text = dt.Rows[0]["TenMon"].ToString();
            }
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            obj_en.MaMon = txtMaMon.Text.Trim();
            obj_en.TenMon = txtTenMon.Text.Trim();
            if (IsInsert == true)
            {
                objMonHoc.MonHoc_Insert(obj_en);
                XtraMessageBox.Show("Thêm thành công", "Thông báo");
                if (LamMoi != null)
                {
                    LamMoi(sender, e);
                    this.Close();

                }
            }
            else
            {
                objMonHoc.MonHoc_Update(obj_en);
                XtraMessageBox.Show("Sửa thành công", "Thông báo");
                if (LamMoi != null)
                {
                    LamMoi(sender, e);
                    this.Close();

                }
            }

        }
    }
}
